package main

import (
	"net/http"
	"com.jinxiula/common"
	"io/ioutil"
	"fmt"
	"encoding/json"
	"strconv"
)

func main() {
	http.HandleFunc("/eth-wallet/netVersion",netVersion)
	http.ListenAndServe(":8080",nil)
}
func netVersion(w http.ResponseWriter, r *http.Request) {
	params :=common.Data()
	params["method"] = "net_version"
	params["params"] = make([]string,0)
	resp:=common.Direct(params)
	defer resp.Body.Close()
	data,_:=ioutil.ReadAll(resp.Body)
	fmt.Println("2)返回的原始数据为:",string(data))
	var result common.Result
	if err:=json.Unmarshal(data,&result);err!=nil{
		w.WriteHeader(http.StatusInternalServerError)
		w.Write([]byte("error"))
	}
	rawData := strconv.Itoa(result.Id)+"->"+result.Jsonrpc+"->"+result.Res
	w.Write([]byte(rawData))
	fmt.Println("3)返回的JSON结果：",result)
}